package com.yaozheng.vocationaltraining.service.impl.set_up;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.set_up.ICheckingVersionView;
import com.yaozheng.vocationaltraining.iview.set_up.IGameRecentView;
import com.yaozheng.vocationaltraining.service.set_up.GameRecentService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

/**
 * Created by moon on 2017/12/5.
 */

@EBean
public class GameRecentServiceImpl implements GameRecentService {
    IGameRecentView iGameRecentView;
    @Override
    public void init(IGameRecentView iGameRecentView) {
        this.iGameRecentView = iGameRecentView;
    }

    @Background
    @Override
    public void gameRecent() {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/pk/game/recent",
                    iGameRecentView.getToken(),
                    new OkHttpClientManager.IBaseViewCallback(new BaseView(iGameRecentView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iGameRecentView.gameRecentSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iGameRecentView.gameRecentError(error);
                        }


                    }));
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iGameRecentView.isResponseResult()) {
                iGameRecentView
                        .gameRecentError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
